import React from "react";
import {Navigate, useRoutes} from "react-router-dom";
import Home from "../pages/Home";
import News from "../pages/News";
import Message from "../pages/Message";
import Details from "../pages/Details";
import About from "../pages/About";
// 1
// export default function (){
//     return useRoutes([
//         {
//             // 首页
//             path:"/home",
//             element:<Home/>,
//             children:[
//                 {
//                     index:true,
//                     element:<Navigate to={"message"}/>
//                 },{
//                     path:"news",
//                     element:<News/>
//                 },{
//                     path:"message",
//                     element: <Message/>,
//                     children:[
//                         {
//                             path:":id",
//                             element:<Details/>
//                         }
//                     ]
//                 }
//             ]
//         },
//         {
//             path:"/about",
//             element: <About/>
//         },{
//             path:"/",
//             element:<Navigate to={"/home"}/>
//         }
//     ])
// }


// 2
export default function useRenderRoutes(){
    return useRoutes([
        {
            // 首页
            path:"/home",
            element:<Home/>,
            children:[
                {
                    index:true,
                    element:<Navigate to={"message"}/>
                },{
                    path:"news",
                    element:<News/>
                },{
                    path:"message",
                    element: <Message/>,
                    children:[
                        {
                            path:":id",
                            element:<Details/>
                        }
                    ]
                }
            ]
        },
        {
            path:"/about",
            element: <About/>
        },{
            path:"/",
            element:<Navigate to={"/home"}/>
        }
    ])
}